<?php

namespace App\Http\Controllers\H5;
use App\Common\ResponseCode;
use App\Http\Controllers\BaseController;
use App\Services\Customer\CustomerService;
use App\Traits\VerifyRequestParam;
use Illuminate\Http\Request;

/**
 * 客户相关控制器
 *
 * @author WangBin
 * @date 2021-09-20
 * @package App\Http\Controllers\H5
 */
class CustomerController extends BaseController
{
    use VerifyRequestParam;

    /**
     * 更新客户信息
     *
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\BusinessException
     */
    public function update(Request $request)
    {
        $customerId = $request->attributes->get('customer_id');
        $update = [
            'nickname' => $request->input('nickname'),
            'head_portrait' => $request->input('head_portrait'),
            'gender' => $request->input('gender')
        ];
        $ret = CustomerService::getInstance()->update($customerId, $update);
        if(!$ret) {
            return $this->fail(ResponseCode::SAVE_FAIL);
        }
        return $this->success();
    }

    /**
     * 获取客户信息
     *
     * @param Request $request
     * @return
     * @throws
     */
    public function get()
    {
        $customerId = $this->verifyInteger('customer_id');
        $ret = CustomerService::getInstance()->getCustomerInfo($customerId);
        return $this->success($ret);
    }

    /**
     * 获取客户财产信息
     *
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\BusinessException
     */
    public function getAssets()
    {
        $customerId = $this->verifyInteger('customer_id');
        $ret = CustomerService::getInstance()->getAssets($customerId);
        return $this->success($ret);
    }
}
